<template>
  <!--  设置-->
  <div class="settings" :style="{ paddingTop: capsuleTop + 'px' }">
    <Return />
    <div class="settings-box">
      <template v-for="(item,index) in settingsList" :key="item.title">
        <div class="settings-box-item" :class="{ 'settings-box-item-active': index !== settingsList.length - 1 }" @click="handleSettingsClick(item,index)">{{ item.title }}</div>
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Return from '@/components/Return.vue'
const capsuleTop = ref(0)
const settingsList = ref([
  {
    title: '帮助中心',
    path: '/pages/HelpCenter',
  },
  {
    title: '关于我们',
    path: '/pages-shift/AboutUs',
  },
  {
    title: '联系我们',
    path: '/pages-shift/ContactUs',
  },
  {
    title: '隐私政策',
    path: '/pages-shift/PrivacyPolicy',
  },
  {
    title: '用户协议',
    path: '/pages-shift/UserAgreement',
  },
  {
    title: '权益保障',
    path: '/pages-shift/Equity',
  },
  {
    title: '退出登录',
    path: '/pages/Settings/PrivacyPolicy',
  },
])
const handleSettingsClick = (item, index) => {
  // 如果是退出登录
  if (item.title === '退出登录') {
    handleLogout()
  } else {
    navTo(item.path)
  }
}
onMounted(() => {
  const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
  capsuleTop.value = menuButtonInfo.bottom + 20
})
const handleLogout = () => {
  uni.showModal({
    title: '提示',
    content: '确定退出登录吗？',
    success: (res) => {
      if (res.confirm) {
        uni.clearStorageSync()
        uni.reLaunch({
          url: '/pages/login?type=logout',
        })
      }
    }
  })
}
</script>

<style lang="scss">
page {
  background: #F5F5F5;
}

.settings {
  padding: 0 40rpx;

  .settings-box {
    width: 670rpx;
    background: #FFFFFF;
    border-radius: 20rpx 20rpx 20rpx 20rpx;
    padding: 0 24rpx;
    box-sizing: border-box;
    .settings-box-item {
      height: 80rpx;
      line-height: 80rpx;
      text-align: center;
      &.settings-box-item-active {
        border-bottom: 2rpx solid #F1F1F2;
      }
    }
  }
}
</style>
